var express = require('express');
var router = express.Router();
var db = require('../bin/db');

router.get('/', function (req, res, next) {
    var authkey = req.query.authkey;
    db.pool.getConnection(function (err, client) {
        if (err){
            res.send(500)
        }else {
            var sql = "SELECT bindtel,Relation_tel from users where authkey = '" + authkey + "'";
            client.query(sql, function (err, rows) {
                if (err){
                    res.send(500)
                }else {
                    var Result = rows[0];
                    if (Result) {
                        var data = {
                            "bindtel": Result.bindtel,
                            "Relation_tel": Result.Relation_tel,
                        };
                        console.log(data);
                        if (data.bindtel && data.Relation_tel) {
                            res.render('phone/phone2', data)
                        } else if (data.bindtel && data.Relation_tel == "") {
                            res.render('phone/phone3', data)
                        } else if (data.bindtel == "" && data.Relation_tel == "" || data.bindtel == null && data.Relation_tel == null) {
                            res.render('phone/phone1', data)
                        }else {
                            res.send("123")
                        }
                    }else {
                        res.send("用户不存在")
                    }
                }
            })
        }

    })
});


router.get('/fasongyanzhengma', function (req, res, next) {
    var tel = req.query.tel;
    res.send(tel);
});
module.exports = router;


